﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using System.Windows;
using System.Xml.Linq;
using System.Linq;

namespace FlashCards.SL.FlashCardCreator.Utils
{
    public class AccentParameters
    {
        public AccentParameters(char oldChar, char newChar, int index)
        {
            OldCharacter = oldChar;
            NewCharacter = newChar;
            Index = index;
        }

        public char OldCharacter { get; set; }
        public char NewCharacter { get; set; }
        public int Index { get; set; }
    }

    public class AccentLettersUtils
    {
        public Dictionary<string, List<string>> GetAccentsForLanguage(string language)
        {
            Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();

            try
            {
                using (var stream = this.GetType().Assembly.GetManifestResourceStream("FlashCards.SL.FlashCardCreator.AccentLettersData.accents.xml"))
                {
                    XElement element = XElement.Load(stream);
                    var setElement = element.Elements("Set").Where(x => x.Attribute("Language").Value == language);
                    if (setElement != null)
                    {
                        var setItems = setElement.Elements("SetItem");

                        foreach (var item in setItems)
                        {
                            var accents = new List<string>();

                            foreach (var accentLetter in item.Elements("Accent"))
                            {
                                accents.Add(accentLetter.Value);
                            }

                            dict.Add(item.Attribute("Letter").Value, accents);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return dict;
        }
    }
}
